<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const arr = [
            { id: "01", pid: "", "name": "老王" },
            { id: "02", pid: "01", "name": "小张" },
            { id: "03", pid: "", "name": "老王" },
            { id: "04", pid: "03", "name": "小张" }
        ]

        
        tranDataToTree()
    </script>
</body>

</html>